package com.bpf.base.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bpf.base.bean.system.TSysSetForm;
import com.bpf.base.bean.system.TSysUserForm;
import com.bpf.base.service.system.TSysSetService;
import com.bpf.base.service.system.TSysUserService;
import com.bpf.base.util.MapUtil;


/**
 * 登录
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping(value = "/")
public class LoginController extends BaseController {

	@Autowired
	private TSysSetService tSysSetService;
	
	@Autowired
	private TSysUserService userService;

	@RequestMapping("/index")
	public String showHome(HttpServletRequest request) {
		return "index";
	}

	@RequestMapping( value={"/login",""})
	public String login(HttpServletRequest request) {
		TSysSetForm form = new TSysSetForm();
		form.setSysId(1);
		request.setAttribute("set", tSysSetService.getAllTSysSet(MapUtil.toMap(form)).get(0));
		return "login";
	}
	
	@RequestMapping("/doLogin")
	@ResponseBody
	public boolean login(@RequestBody TSysUserForm user) {
		return userService.getAllTSysUser(MapUtil.toMap(user)).isEmpty();
	}

	@RequestMapping("/denied")
	public String showDenied() {
		return "denied";
	}

	@RequestMapping("/loggedout")
	public String showLoggedOut(HttpServletRequest request) {
		return "login";
	}

	@RequestMapping("/left")
	public String showLeft(HttpServletRequest request) {
		TSysSetForm form = new TSysSetForm();
		form.setSysId(1);
		request.setAttribute("set", tSysSetService.getAllTSysSet(MapUtil.toMap(form)).get(0));
		return "left";
	}

	@RequestMapping("/top")
	public String showTop(HttpServletRequest request) {
		TSysSetForm form = new TSysSetForm();
		form.setSysId(1);
		request.setAttribute("set", tSysSetService.getAllTSysSet(MapUtil.toMap(form)).get(0));
		return "top";
	}

	@RequestMapping("/main")
	public String showMain() {
		return "main";
	}

	/**
	 * 下面为手机端
	 * */
	
	@RequestMapping("/phone/login")
	public String phoneLogin(){
		return "mobile/login";
	}
}
